Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved matchmaking performance #1156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ratio2
Copy link

@Ratio2 Ratio2 commented Dec 18, 2023

The order of combinations has changed slightly. Now the result is sorted according to the sorting of the input data.

Before these changes, matchmaking with override is very slow with more than 30 players:
players - time in seconds
10 - 1.1
20 - 1.9
22 - 2
24 - 2
26 - 3
28 - 8
30 - 28
32 - 118

The order of combinations has changed slightly. Now the result is sorted according to the sorting of the input data.
@CLAassistant
Copy link

CLAassistant commented Dec 18, 2023

CLA assistant check
All committers have signed the CLA.

@sesposito
Copy link
Member

Hello @Ratio2, can you elaborate a bit more on what this PR is doing to improve performance?

@Ratio2
Copy link
Author

Ratio2 commented Sep 23, 2024

Hello @Ratio2, can you elaborate a bit more on what this PR is doing to improve performance?

Input data:
func combineIndexes(from []*MatchmakerIndex, min, max int)
len(from) = 32
min = 2
max = 2

The function call duration is 118 seconds, since we have complexity O(N*2^N) from the input array size regardless of min/max. The loop for combinationBits := 1; combinationBits < (1 << length); combinationBits++ consists of 2^32 iterations, which is a lot, and there is also an inner loop for element := uint(0); element < length; element++.

The main idea of ​​the change is to not iterate over impossible combinations in the loop. If max = 2, then we are not interested in combinations of 3 or more elements.

iterium.Combinations generates all possible combinations of N elements.
rangeCombinations generates all possible combinations of 1..N elements. If the input is [a, b, c], then the output is [[a], [a, b], [a, c], [b], [b, c], [c]].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants